package com.baseframe.user.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baseframe.tool.result.R;
import com.baseframe.user.entity.BaseUser;
import com.baseframe.user.service.BaseUserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
public class BaseUserFeignImpl implements BaseUseFeign {

    private BaseUserService baseUserService;


    @GetMapping(USER_API+"/find/all-by-username")
    @Override
    public R<BaseUser> findAllByUsername(@RequestParam("username") String username) {
        BaseUser baseUser = baseUserService.getOne(new LambdaQueryWrapper<BaseUser>().eq(BaseUser::getUsername, username));
        return R.data(baseUser);
    }

    @GetMapping(USER_API+"/find/all-by-phone")
    @Override
    public R<BaseUser> findAllByPhone(@RequestParam("phone") String phone) {
        BaseUser baseUser = baseUserService.getOne(new LambdaQueryWrapper<BaseUser>().eq(BaseUser::getPhone, phone));
        return R.data(baseUser);
    }
}
